package com.yc.ice.demo;

import com.zeroc.Ice.Communicator;
import com.zeroc.Ice.Identity;
import com.zeroc.Ice.ObjectAdapter;
import com.zeroc.Ice.Util;
import org.apache.log4j.Logger;

/**
 * Created with IntelliJ IDEA.
 * description:
 * author: yc
 * date: 2020/12/2 21:24
 */
public class Server {
    private static Logger log = Logger.getLogger(Server.class.getSimpleName());

    public static void main(String[] args) {
        int status = 0;
        // 通信器
        Communicator ic = null;
        try {
            // 初始化这个通信器
            ic = Util.initialize(args);
            // 创建ice适配器,将服务调用地址和服务映射起来
            // "HelloServiceAdapter"是适配器名, "default -p 1888"是服务调用的地址
            ObjectAdapter adapter = ic.createObjectAdapterWithEndpoints("HelloServiceAdapter1111","default -p 1888");
            // 将服务的具体实现类servant交给这个适配器
            Object servant = new TestImpl();
            // "HelloIce"--服务接口在ice中注册名,转成唯一标识identity
            Identity id = Util.stringToIdentity("HelloIce");
            adapter.add((com.zeroc.Ice.Object) servant, id);
            // 激活这个适配器
            adapter.activate();

            ic.waitForShutdown();

            log.info("server服务容器启动成功。。。");
        } catch (Exception e) {
            e.printStackTrace();
            status = 1;
        } finally {
            if (ic != null) {
                ic.destroy();
            }
        }
        System.exit(status);

    }
}
